from django.contrib import admin
from .models import MedicationSchedule, MedicationRecord, Reminder

@admin.register(MedicationSchedule)
class MedicationScheduleAdmin(admin.ModelAdmin):
    list_display = ('schedule_name', 'family_member', 'my_medicine', 'frequency_type', 'enabled', 'completion_rate', 'missed_count')
    list_filter = ('frequency_type', 'enabled', 'created_at')
    search_fields = ('schedule_name', 'family_member__user__username')
    readonly_fields = ('completion_rate', 'last_completed_at', 'missed_count', 'delayed_count')

@admin.register(MedicationRecord)
class MedicationRecordAdmin(admin.ModelAdmin):
    list_display = ('medicine', 'schedule', 'status', 'scheduled_time', 'taken_time', 'early_completion')
    list_filter = ('status', 'scheduled_time', 'created_at')
    search_fields = ('medicine__name', 'schedule__schedule_name')
    readonly_fields = ('response_time', 'early_completion')

@admin.register(Reminder)
class ReminderAdmin(admin.ModelAdmin):
    list_display = ('user', 'schedule', 'reminder_time', 'channel', 'status', 'delivery_time')
    list_filter = ('channel', 'status', 'reminder_time')
    search_fields = ('user__username', 'schedule__schedule_name')
    readonly_fields = ('delivery_time', 'read_time', 'retry_count')